const mongoose = require("mongoose");
mongoose.pluralize(null); //去掉集合后面的s
const { Schema, model } = mongoose;
const versionKey = { versionKey: false };
const moment = require("moment");
moment.locale("zh-cn");

// 发起结伴表
const CompanionSchema = new Schema(
  {
    uid: String, //发起人的uid
    description: String, //描述
    image: Array, //图片合集
    city: String, //目的地城市
    full_address: String, //目的地详细地址
    companion_time: String, //结伴时间
    companion_timestamp: Number, //结伴时间时间戳
    number_of_people: Number, //希望人数
    time: {
      //提交时间
      type: String,
      default: () => moment().utcOffset(8).format("YYYY-MM-DD"),
    },
    timestamp: {
      //提交时间时间戳
      type: Number,
      default: () => moment().unix(),
    },
  },
  versionKey
);

// 结伴报名表
const SignupSchema = new Schema(
  {
    signup_id: {
      //关联发起结伴表
      type: mongoose.Types.ObjectId,
      ref: "companion",
      required: true,
    },
    user_uid: String, //报名用户uid
    contact_inform: String, //联系方式
    gender: Number, //性别,0:女，1：男
    introduce: String, //自我介绍
    time: {
      //提交时间
      type: String,
      default: () => moment().utcOffset(8).format("YYYY-MM-DD"),
    },
    timestamp: {
      //提交时间时间戳
      type: Number,
      default: () => moment().unix(),
    },
  },
  versionKey
);

module.exports = {
  modelCompanion: model("companion", CompanionSchema),
  modelSignup: model("signup", SignupSchema),
};
